/* $Id: FileMenuUnitTest.java 63 2010-02-14 13:52:34Z aaron.day $ */
package org.crazydays.gameplan.view;


import javax.swing.JMenuItem;
import javax.swing.JPopupMenu.Separator;

import org.junit.*;
import static org.junit.Assert.*;

import org.crazydays.gameplan.action.ExitApplication;
import org.crazydays.gameplan.db.action.CloseDatabase;
import org.crazydays.gameplan.db.action.CreateDatabase;
import org.crazydays.gameplan.db.action.OpenDatabase;
import org.crazydays.gameplan.db.action.SaveDatabase;
import org.crazydays.gameplan.db.action.SaveDatabaseAs;
import org.crazydays.gameplan.map.action.CreateMapDialog;

/**
 * FileMenuUnitTest
 */
public class FileMenuUnitTest
{
    /**
     * Test initialize().
     */
    @Test
    public void testInitialize()
    {
        // objects
        CreateDatabase createDatabase = new CreateDatabase();
        OpenDatabase openDatabase = new OpenDatabase();
        CloseDatabase closeDatabase = new CloseDatabase();
        SaveDatabase saveDatabase = new SaveDatabase();
        SaveDatabaseAs saveDatabaseAs = new SaveDatabaseAs();
        CreateMapDialog createMapDialog = new CreateMapDialog();
        ExitApplication exitApplication = new ExitApplication();

        // setup
        FileMenu component = new FileMenu();
        component.setCreateDatabase(createDatabase);
        component.setOpenDatabase(openDatabase);
        component.setCloseDatabase(closeDatabase);
        component.setSaveDatabase(saveDatabase);
        component.setSaveDatabaseAs(saveDatabaseAs);
        component.setCreateMapDialog(createMapDialog);
        component.setExitApplication(exitApplication);

        // test
        component.initialize();

        // verify
        assertTrue("createDatabase",
            component.getMenuComponent(0) instanceof JMenuItem);
        assertEquals("createDatabase", createDatabase, ((JMenuItem) component
            .getMenuComponent(0)).getAction());
        assertTrue("openDatabase",
            component.getMenuComponent(1) instanceof JMenuItem);
        assertEquals("openDatabase", openDatabase, ((JMenuItem) component
            .getMenuComponent(1)).getAction());
        assertTrue("closeDatabase",
            component.getMenuComponent(2) instanceof JMenuItem);
        assertEquals("closeDatabase", closeDatabase, ((JMenuItem) component
            .getMenuComponent(2)).getAction());
        assertTrue("separator",
            component.getMenuComponent(3) instanceof Separator);
        assertTrue("saveDatabase",
            component.getMenuComponent(4) instanceof JMenuItem);
        assertEquals("saveDatabase", saveDatabase, ((JMenuItem) component
            .getMenuComponent(4)).getAction());
        assertTrue("saveDatabaseAs",
            component.getMenuComponent(5) instanceof JMenuItem);
        assertEquals("saveDatabaseAs", saveDatabaseAs, ((JMenuItem) component
            .getMenuComponent(5)).getAction());
        assertTrue("separator",
            component.getMenuComponent(6) instanceof Separator);
        assertTrue("createMapDialog",
            component.getMenuComponent(7) instanceof JMenuItem);
        assertEquals("createMapDialog", createMapDialog, ((JMenuItem) component
            .getMenuComponent(7)).getAction());
        assertTrue("separator",
            component.getMenuComponent(8) instanceof Separator);
        assertTrue("exitApplication",
            component.getMenuComponent(9) instanceof JMenuItem);
        assertEquals("exitApplication", exitApplication, ((JMenuItem) component
            .getMenuComponent(9)).getAction());
    }
}
